const router = require('koa-router')();
const {login} = require('../controller/user.js');
const {SuccessModel, ErrorModel} = require('../model/resModel.js');
router.prefix('/api/user')

router.post('/login', async (ctx, next) =>{
  const {username, password} = ctx.request.body
  const data = await login(username, password)
  if (data) {
    console.log(data)
    ctx.session.username = data.username
    ctx.session.realname = data.realname
    ctx.body = new SuccessModel('登陆成功')
      return
    }
   ctx.body =new ErrorModel('登录失败')
})

// router.get('/session-test', function (ctx, next) {
//   if (ctx.session.num == null){
//     ctx.session.num = 0
//   }
//   ctx.session.num++
//   ctx.body ={
//     num:ctx.session.num
//   }
// })

module.exports = router
